<template>
  <div class="wrapper" ref="wrapper">
    <div class="content">
      <slot></slot>
    </div>
  </div>
</template>

<script>
  import BScroll from 'better-scroll'
  export default {
    name: 'betterScroll',
    date() {
      return{
        scroll: null
      }
    },
    props:{
      probeType:{
        type: Number,
        default() {
          return 0
        }
      },
      pullUpLoad:{
        type: Boolean,
        default(){
          return false
        }
      }
    },
    mounted(){
      this.scroll = new BScroll(this.$refs.wrapper,{
        pullUpLoad: this.pullUpLoad,
        probeType: this.probeType,
        mouseWheel: true,
        observeDOM: true, //开启后对content以及content子元素dom改变的探测，当这些dom元素发生变化时，将会触发scroll的refresh方法
        observeImage:true, //根据图片的高度动态刷新高度
        click: true
      })
      this.scroll.on('scroll', (position) => {
        //console.log(position);
        this.$emit('scroll', position)
      })

      this.scroll.on('pullingUp',() => {
        // console.log('上拉触底事件')
        this.$emit('pullingup')
      })

    },
    methods:{
      getScrollY(){
        return this.scroll ? this.scroll.y : 0
      }
    }
  }
</script>

<style>
  /* .wrapper{
    height: 300px;
  }
  .content{
    height: 300px;
  } */
</style>